package com.bumptech.glide.load.engine;

import android.util.Log;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.executor.Prioritized;
import com.bumptech.glide.request.ResourceCallback;

class EngineRunnable
  implements Runnable, Prioritized
{
  private static final String TAG = "EngineRunnable";
  private final DecodeJob<?, ?, ?> decodeJob;
  private volatile boolean isCancelled;
  private final EngineRunnableManager manager;
  private final Priority priority;
  private Stage stage;

  public EngineRunnable(EngineRunnableManager paramEngineRunnableManager, DecodeJob<?, ?, ?> paramDecodeJob, Priority paramPriority)
  {
    this.manager = paramEngineRunnableManager;
    this.decodeJob = paramDecodeJob;
    this.stage = Stage.CACHE;
    this.priority = paramPriority;
  }

  private Resource<?> decode()
    throws Exception
  {
    if (isDecodingFromCache())
      return decodeFromCache();
    return decodeFromSource();
  }

  private Resource<?> decodeFromCache()
    throws Exception
  {
    try
    {
      Resource localResource2 = this.decodeJob.decodeResultFromCache();
      localResource1 = localResource2;
      if (localResource1 == null)
        localResource1 = this.decodeJob.decodeSourceFromCache();
      return localResource1;
    }
    catch (Exception localException)
    {
      while (true)
      {
        boolean bool = Log.isLoggable("EngineRunnable", 3);
        Resource localResource1 = null;
        if (bool)
        {
          Log.d("EngineRunnable", "Exception decoding result from cache: " + localException);
          localResource1 = null;
        }
      }
    }
  }

  private Resource<?> decodeFromSource()
    throws Exception
  {
    return this.decodeJob.decodeFromSource();
  }

  private boolean isDecodingFromCache()
  {
    return this.stage == Stage.CACHE;
  }

  private void onLoadComplete(Resource paramResource)
  {
    this.manager.onResourceReady(paramResource);
  }

  private void onLoadFailed(Exception paramException)
  {
    if (isDecodingFromCache())
    {
      this.stage = Stage.SOURCE;
      this.manager.submitForSource(this);
      return;
    }
    this.manager.onException(paramException);
  }

  public void cancel()
  {
    this.isCancelled = true;
    this.decodeJob.cancel();
  }

  public int getPriority()
  {
    return this.priority.ordinal();
  }

  public void run()
  {
    if (this.isCancelled);
    while (true)
    {
      return;
      Object localObject = null;
      try
      {
        Resource localResource2 = decode();
        localResource1 = localResource2;
        if (this.isCancelled)
        {
          if (localResource1 == null)
            continue;
          localResource1.recycle();
        }
      }
      catch (Exception localException)
      {
        Resource localResource1;
        while (true)
        {
          if (Log.isLoggable("EngineRunnable", 2))
            Log.v("EngineRunnable", "Exception decoding", localException);
          localObject = localException;
          localResource1 = null;
        }
        if (localResource1 == null)
        {
          onLoadFailed(localObject);
          return;
        }
        onLoadComplete(localResource1);
      }
    }
  }

  static abstract interface EngineRunnableManager extends ResourceCallback
  {
    public abstract void submitForSource(EngineRunnable paramEngineRunnable);
  }

  private static enum Stage
  {
    static
    {
      Stage[] arrayOfStage = new Stage[2];
      arrayOfStage[0] = CACHE;
      arrayOfStage[1] = SOURCE;
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.bumptech.glide.load.engine.EngineRunnable
 * JD-Core Version:    0.6.2
 */